export default {
  name: 'BaseDragItem',
  props: {
    attrs: Object,
    extendAttrs: Object,
    type: String,
    properties: Object,
    children: Array,
    form: Object,
    itemChoose: Function,
    id: String,
    dragGroupName: String,
    selectId: String,
    checkClass: String,
    dragClass: String,
    logicControl: {
      type: Boolean,
      default: true
    }
  },

  methods: {
    findKeyedItems(array) {
      if (this.properties && this.properties.key) {
        let labels = ''
        let vals = ''
        if (this.properties.dictType == '3') {
          this.extendAttrs.data.forEach((dict) => {
            if (labels.length == 0) {
              labels = dict.label
              vals = dict.value
            } else {
              labels = labels + ',' + dict.label
              vals = vals + ',' + dict.value
            }
          })
        }
        array.push({
          attrs: this.attrs,
          extendAttrs: this.extendAttrs,
          type: this.type,
          properties: this.properties,
          children: this.children,
          id: this.id,
          localData: {
            labels: labels,
            values: vals
          }
        })
      }
    },
    findQueryableItemHtml(obj, space) {
      return obj
    },
    findItemById(id) {
      return null
    },
    findItemByKey(key) {
      return null
    },
    removeItemById(id) {},
    isShow(properties) {
      if (this.logicControl && properties.ifCondition) {
        // eslint-disable-next-line no-eval
        return eval(
          '(formValue,$hasRole,$hasPermission,disableItem)=>{return ' + properties.ifCondition + '}'
        )(this.form, this['$hasRole'], this['$hasPermission'], false)
      }

      return true
    },
    buildHtmlAttr(disabled, attrs, space) {
      let str = ''
      Object.keys(attrs).forEach((key) => {
        const value = attrs[key]
        if (value != null) {
          if (typeof value === 'string') {
            str = str + space + key + '="' + value + '"'
          } else if (Array.isArray(value)) {
            str = str + space + ':' + key + '="' + JSON.stringify(value).replace(/"/g, "'") + '"'
          } else if (Object.prototype.toString.call(value) === '[object Object]') {
            str = str + space + ':' + key + '="' + JSON.stringify(value).replace(/"/g, "'") + '"'
          } else {
            str = str + space + ':' + key + '="' + value + '"'
          }
          str = str + '\r\n'
        }
      })
      return str
    }
  }
}
